package org.gd.hellojavacore.tests;

import java.lang.reflect.Field;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;

import static java.lang.reflect.Modifier.*;

public class LocaleTest {

    public static void main(String...args) {
        try {
            test2();
        } catch (Throwable e) {
            e.printStackTrace(System.err);
        }
    }

    private static void test1() {
        Locale locale = new Locale("ru");
        System.out.println(locale.toString().toUpperCase());

        locale = Locale.forLanguageTag("de");
        System.out.println(locale.hashCode());
        System.out.println(Locale.GERMANY.hashCode());
        System.out.println("getCountry: " + locale.getCountry());
        System.out.println("getLanguage: " + locale.getLanguage());
    }

    private static void test2() throws IllegalAccessException {
        Set<Locale> localeSet = new TreeSet<>();
        for(Field field: Locale.class.getDeclaredFields()) {
            if(field.getType().equals(Locale.class)
                    && isStatic(field.getModifiers())
                    && isFinal(field.getModifiers())) {
                localeSet.add((Locale) field.get(null));
            }
        }

    }
}
